/**
 * BBD Service Inc
 * All Rights Reserved @2018
 */
package com.bbd.merchant.guide.galaxy.util;

import com.bbd.merchant.guide.galaxy.constant.Constants;
import com.bbd.merchant.guide.galaxy.exceptin.GalaxyException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

/**
 *
 *
 * @author tianyuliang
 * @version $Id: BaseUtils.java, v0.1 2018-08-01 11:36 tianyuliang Exp $$
 */
public class BaseUtils {

    /**
     * 读取输入的命令列表
     * @param fileName
     * @return
     * @throws IOException
     */
    public static List<String> readLines(String fileName) throws GalaxyException {
        InputStream inputStream = null;
        try {
            inputStream = FileUtils.class.getClassLoader().getResourceAsStream(fileName);
            if (inputStream == null) {
                throw new GalaxyException("the input file " + fileName + " is not exist!");
            }
            List<String> commends = IOUtils.readLines(inputStream, Charset.forName(Constants.UTF8));
            return commends == null ? new ArrayList<>() : commends;
        } catch (GalaxyException e) {
            throw e;
        } catch (IOException e) {
            throw new GalaxyException("read input data error. fileName=" + fileName, e);
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
    }

}
